package business.html.fulldoc;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import business.html.citationReport.ScrappingPage;

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlHiddenInput;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSpan;
import com.gargoylesoftware.htmlunit.html.HtmlTable;
import com.gargoylesoftware.htmlunit.html.HtmlTableCell;
import com.gargoylesoftware.htmlunit.html.HtmlTableRow;

import com.gargoylesoftware.htmlunit.html.HtmlSelect;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement;

/**
 * Pagina para abrir el listado de Subject Categories y refinado de las busquedas con los mismos
 * @author 53385255R
 *
 */
public class DateDocsPage extends ScrappingPage {

	/**
	 * constructor
	 * @param page
	 */
	public DateDocsPage(HtmlPage page) {
		super(page);
	}
	
	/**
	 *  constructor
	 * @param url
	 * @throws FailingHttpStatusCodeException
	 * @throws MalformedURLException
	 * @throws IOException
	 */
	public DateDocsPage(String url) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
		super(url);
	}
	
	/**
	 *  constructor
	 * @param url
	 * @throws FailingHttpStatusCodeException
	 * @throws IOException
	 */
	public DateDocsPage(URL url) throws FailingHttpStatusCodeException, IOException  {
		super(url);
	}
	
	/**
	 * Busca y devuelve el dato Utid del registro
	 * @return Utid del registro
	 * @throws IOException
	 */
	public String seekUtid() throws IOException, RuntimeException {
		String utid="";
		if(_page!=null){
			HtmlForm form= _page.getFormByName("mark_records_form");
			HtmlHiddenInput idDoc=form.getInputByName("recordID");
			utid=idDoc.getValueAttribute().replace("WOS", "ISI");
		}
				
		
		return utid;
		
	}
	
		
	public String findValueInCell(){
		
		HtmlTable table = _page.getHtmlElementById("FullRecDataTable");
		for (HtmlTableRow row : table.getRows()) {
		System.out.println("Found row");
		    for (HtmlTableCell cell : row.getCells()) {
		       System.out.println("   Found cell: " + cell.asText());
		    }
		}
		return null ;
	}
	/**
	 * Refresca la pagina
	 * @throws IOException
	 */
	public void refresh() throws IOException {
		_page = (HtmlPage) _page.refresh();
		
	}
	
	
}
